package com.ruoyi.core.entity;

import com.ruoyi.core.constant.Constant;
import lombok.Data;

@Data
public class Output<T> {
    /**
     * 是否成功
     */
    protected boolean success;
    /**
     * 响应码
     */
    protected Integer code;
    /**
     * 响应提示信息
     */
    protected String msg;
    /**
     * 返回数据对象
     */
    protected T data;

    public Output() {
    }

    public static <T> Output<T> success(T data) {
        Output<T> output = new Output<T>();
        output.setSuccess(true);
        output.setCode(Constant.CODE_SUCCESS);
        output.setMsg("操作成功");
        output.setData(data);
        return output;
    }

    public static Output<Object> success() {
        Output<Object> output = new Output<Object>();
        output.setSuccess(true);
        output.setCode(Constant.CODE_SUCCESS);
        output.setMsg("操作成功");
        return output;
    }


    public static Output<Object> fail(Integer code, String message) {
        Output<Object> output = new Output<Object>();
        output.setSuccess(false);
        output.setCode(code);
        output.setMsg(message);
        return output;
    }

    public static Output<Object> fail(String message) {
        return fail(Constant.CODE_FAIL, message);
    }

}
